/***********************************************************************
	filename: 	DaterUserManager.h
	created:	21/4/2012
	author:		4Ys
	
	purpose:	Defines the interface for the UserManager object
*************************************************************************/
#ifndef _DaterUserManager_h_
#define _DaterUserManager_h_

#include "DaterUser.h"
#include "DaterSingleton.h"

#include <map>
#include <string>

namespace Dater
{
	/*!
	\brief
		The UserManager class describes an object that manages creation and lifetime of User objects.
	*/
	class UserManager : public Singleton< UserManager>
	{
	public:
		/*!
		\brief
			Construct a new UserManager object.
		*/
		UserManager(void);

		/*!
			Destructor for UserManager object.
		*/
		~UserManager(void);

		/*!
		\brief
			Set current User object of Dater.

			Called in login case.

		\param accountID
			ID of the acount.

		\param passWord
			PassWord of the account.

		\return
			A User pointer point to the current User
		*/
		void setCurrentUser(User* user);

		/*!
		\brief
			Get current User object of Dater.

		\return
			A user pointer point ot the currentUser
		*/
		User* getCurrentUser();

		/*!
		\brief
			Try to register an account.

			Called in register case.

		\param name
			User name to be registered

		\param Email
			- Email to register the account
			- Have to ended with @sjtu.edu.cn

		\param accountID
			Account ID registered to login Dater

		\param passWord
			Account password registered to login Dater

		\return
			The registered User Object if register successfully.
		*/
		//User* registerUser(const std::string& name, const std::string& Email, const std::string& accountID,
			//const std::string& passWord);

		/*!
		\brief
			Add related User object used in Dater
			May be tem object, and it will be removed soon

		\param name
			The name of the User

		\param state
			The state of the User

		\param uid
			The unique ID of the User

		\return
			A pointer point to the added User
		*/
		User* addRelatedUser(int uid, const std::string& hypocorism,
			const std::string& gender, const std::string& birthday, const std::string& state = "");

		/*!
		\brief
			Remove related User in Dater

		\param theUser
			A pointer of the User to be removed

		\return
			Nothing
		*/
		void removeRelatedUser(User* theUser);

		/*!
		\brief
			Remove related User in Dater

		\param uid
			Unique ID of the User to be removed.

		\return
			nothing
		*/
		void removeRelatedUser(int uid);

		/*!
		\brief
			Get the pointer of a specific User

		\param uid
			Unique ID of the User to be getted

		\return
			A pointer of the User
		*/
		User* getUser(int uid);

		/*!
		\brief
			Judge whether the User of given uid is related

		\param uid
			Unique ID of the User to be queryed

		\return
			Whether the User is related
		*/
		bool isUserRelated(int uid);

		/*!
		\brief
			Remove all User object

			Should only be called in Destructor
		*/
		void removeAllUsers(void);

	private:
		typedef std::map<unsigned long, User*> RelatedUserRegistry;//! The registry vector of all User object
		RelatedUserRegistry _relatedUserRegistry;

		User* _currentUser;
	};

}

#endif